package com.kedou.sdk.ui.model;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;

import java.util.List;

public class ActivityPageInfo implements Parcelable {

    public static final String DEFAULT_URL = "https://www.7749g.com";
    public static final Creator<ActivityPageInfo> CREATOR = new Creator<ActivityPageInfo>() {
        @Override
        public ActivityPageInfo createFromParcel(Parcel source) {
            return new ActivityPageInfo(source);
        }

        @Override
        public ActivityPageInfo[] newArray(int size) {
            return new ActivityPageInfo[size];
        }
    };

    @SerializedName("key")
    private int currentUrlIndex;

    @SerializedName("show_url_list")
    private List<String> activityPageUrlList;

    public ActivityPageInfo() {
    }

    protected ActivityPageInfo(Parcel in) {
        this.currentUrlIndex = in.readInt();
        this.activityPageUrlList = in.createStringArrayList();
    }

    public int getCurrentUrlIndex() {
        return currentUrlIndex;
    }

    public void setCurrentUrlIndex(int currentUrlIndex) {
        this.currentUrlIndex = currentUrlIndex;
    }

    public List<String> getActivityPageUrlList() {
        return activityPageUrlList;
    }

    public void setActivityPageUrlList(List<String> activityPageUrlList) {
        this.activityPageUrlList = activityPageUrlList;
    }

    public String getCurrentPageUrl() {
        return getPageUrl(currentUrlIndex);
    }

    public String getPageUrl(int position) {
        if(this.activityPageUrlList != null && !activityPageUrlList.isEmpty()){
            position = Math.max(Math.min(position, activityPageUrlList.size() - 1), 0);
            return activityPageUrlList.get(position);
        }
        return DEFAULT_URL;
    }

    public int urlSize(){
        return activityPageUrlList != null ? activityPageUrlList.size() : 0;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.currentUrlIndex);
        dest.writeStringList(this.activityPageUrlList);
    }
}
